<?php

/**
 * 移动端上传图片公共函数
 * @modify  wenhui 2016-11-28 创建
 */
function mobileUpload($file, $config) {
    // 判断是否有上传图片
    $uploadedFile = false;
    if (isset($file['tmp_name'])) {
        $uploadedFile = true;

        // 处理上传图片
        $configInfo = C($config);
        $config = array(
            'maxSize' => $configInfo['maxSize'],
            'rootPath' => $configInfo['rootPath'],
            'savePath' => $configInfo['savePath'],
            'exts' => $configInfo['exts'],
            'subName' => array('date', 'Ymd'),
        );
        $upload = new \Think\Upload($config);
        $info = $upload->upload();
        if (!$info) {
            $this->returnJson(500, 511, $upload->getError());
        }
        $filename = '/Uploads/' . $info['file']['savepath'] . $info['file']['savename'];
    }
    $imageUrl = $uploadedFile ? $filename : null;
    return $imageUrl;
}
